package config

import (
	"os"

	"github.com/pkg/errors"
	"github.com/spf13/viper"
)

// ReadYamlConfigs read multiple config files using viper
func ReadYamlConfigs(configFiles ...string) error {
	viper.SetConfigType("yaml")

	for _, configFile := range configFiles {
		f, err := os.Open(configFile)
		if err != nil {
			return errors.Wrapf(err, "Open config file")
		}
		if err = viper.MergeConfig(f); err != nil {
			return errors.Wrap(err, "Read config")
		}
	}

	return nil
}
